package dk.mobiletrainer.ui.panels;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.toedter.calendar.JDateChooser;

public class WorkoutPanel extends JPanel {
	private JTextField textFieldWorkoutName;
	private JDateChooser startDate, endDate, weigtExerciseDate, cardioExerciseDate;
	private JTextField textFieldWeightExerciseName, textFieldCardioExcerciseName, textFieldSets, 
						textFieldReps, textFieldDuration; 
	private JButton buttonAddWeightExercise, buttonAddCardioExercise; 
	private JList listOfExercises;
	
	public WorkoutPanel(){
		buildPanel();
	}

	private void buildPanel() {
		this.setLayout(new BorderLayout());
		this.add(buildWorkoutPanel(), BorderLayout.CENTER);
		this.setBackground(Color.WHITE);
	}
	
	private JPanel buildWorkoutPanel(){
		String[] test = {"Exercise 1", "Exercise 2"};
		
		textFieldWorkoutName 			= new JTextField();
		startDate 						= new JDateChooser();
		endDate							= new JDateChooser();
		
		textFieldWeightExerciseName 	= new JTextField();
		textFieldSets 					= new JTextField();
		textFieldReps 					= new JTextField();
		weigtExerciseDate				= new JDateChooser();
		buttonAddWeightExercise			= new JButton("Add exercise");
		
		textFieldCardioExcerciseName 	= new JTextField();
		textFieldDuration 				= new JTextField();
		cardioExerciseDate				= new JDateChooser();
		buttonAddCardioExercise			= new JButton("Add exercise");
		
		listOfExercises					= new JList( test );
		
		FormLayout layout = new FormLayout(
				"right:max(50dlu;p), 4dlu, 75dlu, 7dlu, right:p, 4dlu, 75dlu",
				"p, 5dlu, p, 3dlu, p, 3dlu, p, 7dlu, p, 2dlu, p, 3dlu, p, 5dlu, p, 3dlu, p, 3dlu, p, 5dlu, p, 3dlu, p, 3dlu, p");

		PanelBuilder builder = new PanelBuilder(layout);
		builder.setDefaultDialogBorder();
		CellConstraints cc = new CellConstraints();
		
		builder.addSeparator("Workout details", cc.xyw(1, 1, 7));
		
		builder.addLabel("Name", cc.xy (1, 3));
		builder.add(textFieldWorkoutName, cc.xy (3, 3));
		
		builder.addLabel("start date", cc.xy (1, 5));
		builder.add(startDate, cc.xy (3, 5));
		builder.addLabel("end date", cc.xy (5, 5));
		builder.add(endDate, cc.xy (7, 5));
		
		builder.addSeparator("Weight exercise", cc.xyw(1, 9, 7));
		
		builder.addLabel("Name", cc.xy (1, 11));
		builder.add(textFieldWeightExerciseName, cc.xy (3, 11));
		builder.addLabel("sets", cc.xy (5, 11));
		builder.add(textFieldSets, cc.xy (7, 11));
		
		builder.addLabel("reps", cc.xy (1, 13));
		builder.add(textFieldReps, cc.xy (3, 13));
		builder.addLabel("Date", cc.xy (5, 13));
		builder.add(weigtExerciseDate, cc.xy (7, 13));
	
		builder.add(buttonAddWeightExercise, cc.xy(7, 15));
		
		builder.addSeparator("Cardio excercise", cc.xyw(1, 17, 7));
		
		builder.addLabel("Name", cc.xy (1, 19));
		builder.add(textFieldCardioExcerciseName, cc.xy (3, 19));
		builder.addLabel("Duration", cc.xy (5, 19));
		builder.add(textFieldDuration, cc.xy (7, 19));
		
		builder.addLabel("Date", cc.xy(1, 21));
		builder.add(cardioExerciseDate, cc.xy (3, 21));
		builder.add(buttonAddCardioExercise, cc.xy(7, 21));
		
		builder.addSeparator("Added exercises", cc.xyw(1, 23, 7));
		
		builder.add(listOfExercises, cc.xyw(1, 25, 7));
			
		return builder.getPanel();		
	}
}
